package com.alisoft.nano.seda;

import com.alisoft.nano.seda.monitor.StageMonitor;
import com.alisoft.nano.seda.notification.StageNotificationListener;

/**
 * One stage in SEDA
 * 
 * @author zhimin.chenzm
 *
 * @param <T> the type of work unit
 */
public interface Stage<T> extends StageMBean {

    /**
     * Post one event to this stage.
     * 
     * @param event
     * @return
     * @throws InterruptedException
     */
	boolean post(Event<T> event) throws InterruptedException;

	/**
	 * 
	 * 
	 * @return the name of this stage. The name is unique in one event machine.
	 */
	String getName();

	/**
	 * Start this stage.
	 */
	void start();

	/**
	 * Stop this stage.
	 */
	void stop();	

	/**
	 * Check whether this stage is started.
	 * @return
	 */
	boolean isStarted();

	/**
	 * Set the event handler to process the work-unit
	 * 
	 * @param eventHandler
	 */
	void setEventHandler(EventHandler<T> eventHandler);
	
	/**
	 * 
	 * @param listener
	 */
	void addStageNotificationListener(StageNotificationListener<T> listener);
	
	
	void setStageMonitor(StageMonitor<T> stageMonitor);
    
    StageMonitor<T> getStageMonitor();
}
